<p>Serializing a non-<code>static</code> inner class will result in an attempt at serializing the outer class as well. If the outer class is not
serializable, then serialization will fail, resulting in a runtime error.</p>
<p>Making the inner class <code>static</code> (i.e. "nested") avoids this problem, therefore inner classes should be <code>static</code> if possible.
However, you should be aware that there are semantic differences between an inner class and a nested one:</p>
<ul>
  <li> an inner class can only be instantiated within the context of an instance of the outer class. </li>
  <li> a nested (<code>static</code>) class can be instantiated independently of the outer class. </li>
</ul>
<h2>Noncompliant Code Example</h2>
<pre>
public class Pomegranate {
  // ...

  public class Seed implements Serializable {  // Noncompliant; serialization will fail
    // ...
  }
}
</pre>
<h2>Compliant Solution</h2>
<pre>
public class Pomegranate {
  // ...

  public static class Seed implements Serializable {
    // ...
  }
}
</pre>
<h2>See</h2>
<ul>
  <li> <a href="https://wiki.sei.cmu.edu/confluence/x/ZTdGBQ">CERT SER05-J.</a> - Do not serialize instances of inner classes </li>
</ul>

